var util = require('./we7/resource/js/util.js');
App({
  globalData:{
    tabbar: {
      color: "#242424",
      selectedColor: "#038DE4",
      backgroundColor: "#ffffff",
      borderStyle: "#d7d7d7",
      list: [],
      position: "bottom"
    },
    userInfo:{}
  },
  setFromId:function(data){
    util.request({
      url: 'Index/Index/from_id',
      data: {
        openid: data.openid,
        form_id: data.formId
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log('存储成功');
      }
    })
  },
  startpay: function (data) {
    const that = this;
    wx.requestPayment({
      'timeStamp': data.timeStamp,
      'nonceStr': data.nonceStr,
      'package': data.package,
      'signType': 'MD5',
      'paySign': data.paySign,
      'success': function (res) {
        if (res.errMsg === "requestPayment:ok"){
          wx.showToast({
            title: '支付成功',
            icon: 'success',
            duration: 2000
          })
          wx.navigateBack({
            delta: 1,
          })
        }
      },
      'fail':function(res){
        wx.showToast({
          title: '支付失败',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  onLaunch:function(res){},
  onShow:function(res){},
  onHide:function(){},
  setchangeTabBar:function(){
    this.changeTabBar();
  },
  onError:function(msg){},
  util: util,
  userInfo:{},
  changeTabBar:function(){
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0){
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabbar;
    for(var i=0;i<tabBar.list.length;i++){
      tabBar.list[i].selected = false;
      if(tabBar.list[i].pagePath==_pagePath){
        tabBar.list[i].selected = true;
      }
    }
    _curPage.setData({
      tabbar: tabBar
    });
  },
  siteInfo: require('siteinfo.js')
});